FMTS=magproto.o gpx.o geo.o gpsman.o mapsend.o mapsource.o \
gpsutil.o tiger.o pcx.o csv.o cetus.o gpspilot.o magnav.o \
- psp.o mxf.o holux.o garmin.o
+ psp.o mxf.o holux.o garmin.o ozi.o
JEEPS=jeeps/gpsapp.o jeeps/gpscom.o jeeps/gpsfmt.o jeeps/gpsinput.o \
jeeps/gpsmath.o jeeps/gpsmem.o \
jeeps/gpsproj.o jeeps/gpsprot.o jeeps/gpsread.o \
jeeps/gpsrqst.o jeeps/gpssend.o jeeps/gpsserial.o jeeps/gpsutil.o
-OBJS=main.o queue.o route.o waypt.o util.o vecs.o mkshort.o \
- coldsync/util.o coldsync/pdb.o $(GARMIN) $(JEEPS) $(FMTS)
+COLDSYNC=coldsync/util.o coldsync/pdb.o
+
+OBJS=main.o queue.o route.o waypt.o util.o vecs.o mkshort.o csv_util.o \
+ $(COLDSYNC) $(GARMIN) $(JEEPS) $(FMTS)
all: gpsbabel
util.o: util.c defs.h queue.h
vecs.o: vecs.c defs.h queue.h
waypt.o: waypt.c defs.h queue.h
+psp.o: psp.c defs.h queue.h
+mxf.o: mxf.c csv_util.c defs.h queue.h csv_util.h
+ozi.o: ozi.c csv_util.c defs.h queue.h csv_util.h
+csv_util.o: csv_util.c csv_util.h defs.h
complies with (at least) Maptech Terrain Navigator, Terrain
Professional, Take a Hike, and ExpertGPS import/export MFX.
- Maptech MXF
- Maptech's MXF is a CSV on steroids. Contributed by Alex Mottram.
+ OZI
+
+ OziExplorer Waypoint Format - Another CSV format file.
+ Tested against OziExplorer v 3.90.3a / Shareware.
+ Contributed by Alex Mottram
COMMON USAGE
*/
#include "defs.h"
+#include "csv_util.h"
#include <ctype.h>
static FILE *file_in;
static void
data_read(void)
{
- char desc[80];
- char *odesc = desc;
- double lat,lon;
+ char buff[1024];
+ char *s;
+ int i;
waypoint *wpt_tmp;
+ int linecount = 0;
- while( fscanf(file_in, "%lf,%lf,%80[^\n]",
- &lat, &lon, desc) > 0) {
- wpt_tmp = calloc(sizeof(*wpt_tmp),1);
- if (wpt_tmp == NULL) {
+ do {
+ linecount++;
+ memset(&buff, '\0', sizeof(buff));
+ fgets(buff, sizeof(buff), file_in);
+
+ if (strlen(buff)) {
+
+ wpt_tmp = calloc(sizeof(*wpt_tmp), 1);
+ if (wpt_tmp == NULL) {
fatal(MYNAME ": cannot allocate memory\n");
+ }
+
+ s = buff;
+ /* data delimited by commas, not enclosed */
+ s = csv_lineparse(s, ",", "", linecount);
+
+ i = 0;
+
+ while (s) {
+ switch (i) {
+ case 0:
+ wpt_tmp->position.latitude.degrees = atof(s);
+ break;
+ case 1:
+ wpt_tmp->position.longitude.degrees = atof(s);
+ break;
+ case 2:
+ wpt_tmp->description = strdup(s);
+ if (! wpt_tmp->description)
+ fatal(MYNAME, ": cannot allocate memory\n");
+ wpt_tmp->description = csv_stringtrim(wpt_tmp->description, " ");
+ break;
+ default:
+ fprintf (stderr, "%s: Warning: unmapped data fields on line %d.\n",
+ MYNAME, linecount);
+ break;
+ }
+ i++;
+
+ s = csv_lineparse(NULL, ",", "", linecount);
}
- while (*odesc == ' ' || *odesc == '\t') {
- odesc++;
- }
- wpt_tmp->shortname = strdup(odesc);
+
wpt_tmp->creation_time = time(NULL);
-
- wpt_tmp->position.longitude.degrees = lon;
- wpt_tmp->position.latitude.degrees = lat;
-
waypt_add(wpt_tmp);
+
+ } else {
+ /* empty line */
}
+
+ } while (!feof(file_in));
}
static void
lon = wpt->position.longitude.degrees;
lat = wpt->position.latitude.degrees;
+ if (wpt->description)
+ wpt->description = csv_stringclean(wpt->description, ",\"");
fprintf(file_out, "%08.5f, %08.5f, %s\n",
lat,
*/
#include "defs.h"
+#include "csv_util.h"
#include <ctype.h>
#define MYNAME "MXF"
static FILE *file_in;
static FILE *file_out;
-static char *
-csvstringclean(char * string)
-{
- static char * p1 = NULL;
- char * p2 = NULL;
-
- if (! string) {
- return (string); /* :) */
- }
-
- p2 = string;
-
- while ((*p2) && (p2++)) { }
- p2--;
-
- while (isspace(*p2)) {
- *p2 = '\0';
- p2--;
- }
-
- p1 = string;
-
- while (isspace(*p1)) {
- p1++;
- }
-
- /* yank quotes in pairs only if they are bounding us */
- while ((*p1 == '"') && (*p2 == '"')) {
- *p2 = '\0';
- p2--;
- p1++;
- }
-
- return (p1);
-}
-
-/* string parser. sorta like strtok with quotes & pointers.. */
-/* designed to handle quoted and delimited data within quotes. */
-static char *
-csvparse(char *stringstart, char *delimiter)
-{
- char *sp;
- static char *p = NULL;
- static char *tmp = NULL;
- size_t dlen;
- int quotedepth = 0;
- short int dfound;
-
- if (!p) {
- p = stringstart;
-
- if (!p) {
- return (NULL);
- }
- }
-
- if (tmp) {
- free(tmp);
- tmp = NULL;
- }
-
- sp = p;
-
- dlen = strlen(delimiter);
- dfound = 0;
-
- while ((*p) && (! dfound)) {
- if (*p == '"') {
- if (quotedepth)
- quotedepth--;
- else
- quotedepth++;
- }
-
- if ((!quotedepth) && (strncmp(p, delimiter, dlen) == 0)) {
- dfound = 1;
-
- } else {
- p++;
- }
-
- }
-
- tmp = (char *) calloc((p - sp) + 1, sizeof(char));
-
- if (! tmp) {
- fatal(MYNAME ": cannot allocate memory\n");
- }
-
- strncpy(tmp, sp, (p - sp));
-
- if (dfound) {
- /* skip over the delimiter */
- p += dlen;
- } else {
- /* end of the line */
- p = NULL;
- }
-
- return (tmp);
-}
-
static void
rd_init(const char *fname)
{
static void
data_read(void)
{
- char buff[256];
+ char buff[1024];
char *s;
waypoint *wpt_tmp;
int i;
fatal(MYNAME ": cannot allocate memory\n");
}
+ /* data delimited by commas, possibly enclosed in quotes. */
s = buff;
- s = csvparse(s, ", ");
+ s = csv_lineparse(s, ",", "\"", linecount);
i = 0;
while (s) {
wpt_tmp->position.longitude.degrees = atof(s);
break;
case 2:
- wpt_tmp->description = strdup(csvstringclean(s));
+ wpt_tmp->description = strdup(s);
+ if (! wpt_tmp->description)
+ fatal(MYNAME, ": cannot allocate memory\n");
+
+ wpt_tmp->description = csv_stringtrim(wpt_tmp->description, "");
break;
case 3:
- wpt_tmp->shortname = strdup(csvstringclean(s));
+ wpt_tmp->shortname = strdup(s);
+ if (! wpt_tmp->shortname)
+ fatal(MYNAME, ": cannot allocate memory\n");
+
+ csv_stringtrim(wpt_tmp->shortname, "");
break;
case 4:
/* ignore. another name-type */
}
i++;
- s = csvparse(NULL, ", ");
+ s = csv_lineparse(NULL, ",", "\"", linecount);
}
if (i != 7) {
int icon = 47; /* default to "dot" */
const char *color_hex = "ff0000";
+ csv_stringclean(wpt->shortname, ",\"");
+ csv_stringclean(wpt->description, ",\"");
+
fprintf(file_out, "%08.5f, %08.5f, \"%s\", \"%s\", \"%s\", %s, %d\n",
wpt->position.latitude.degrees, wpt->position.longitude.degrees,
wpt->description, wpt->shortname, wpt->description,
${PNAME} -i geo -f geocaching.loc -o mxf -F /tmp/mxf.mxf
diff /tmp/mxf.mxf reference
+# OZI (OziExplorer 1.1) file format
+${PNAME} -i geo -f geocaching.loc -o ozi -F /tmp/ozi.ozi
+diff /tmp/ozi.ozi reference
+
extern ff_vecs_t garmin_vecs;
extern ff_vecs_t mxf_vecs;
extern ff_vecs_t holux_vecs;
+extern ff_vecs_t ozi_vecs;
static
vecs_t vec_list[] = {
"holux",
"Holux (gm-100) .wpo Format"
},
+ {
+ &ozi_vecs,
+ "ozi",
+ "OziExplorer Waypoint"
+ },
{
NULL,